// import { question } from "readline-sync";
let rs = require('readline-sync')
import { Poker } from "./pokerts";
import { Card } from "./cardts";

let mapPrize: Map<string, number> = new Map()
mapPrize.set('同花顺', 100)
mapPrize.set('四条', 25)
mapPrize.set('满堂红', 10)
mapPrize.set('同花', 5)
mapPrize.set('顺子', 4)
mapPrize.set('三条', 3)
mapPrize.set('两对', 2)
mapPrize.set('一对', -1)
mapPrize.set('无对', -2)
let poker: Poker = new Poker()
let score: number = 100
while (true) {
    let bet_times: number = rs.question('please give your bet:')//赌注押的倍数bet_times
    score = score - bet_times
    console.log(`您当前的分数是：${score}`);
    let one_hand: Array<Card> = poker.get_one_hand()
    poker.output_onehand(one_hand)
    console.log();
    let swap_cards = rs.question('\n please input card no what you wang to change(1-5),if you input 0,then game over,split by blank space:\n')
    if (swap_cards === '0') {//停止游戏
        console.log('游戏结束！');
        break
    }
    if (swap_cards.length !== 0) {//玩家不想换牌，只是输入了一个回车,回车时值为0
        let swap_cards_arr: string[] = swap_cards.split(' ')
        let begin_index: number = 5
        for (let card_index of swap_cards_arr) {
            let from_index = parseInt(card_index)
            // card_index--
            one_hand.splice(from_index, 1, poker.get_one_card(begin_index++))
        }
        poker.output_onehand(one_hand)
    }
    let card_type: string = poker.get_type(one_hand)
    console.log();
    console.log(card_type);
    let tmp_score: number | undefined = mapPrize.get(card_type)
    if (tmp_score != undefined) {
        console.log(tmp_score * bet_times);
        score += (tmp_score * bet_times)
    }
}
